function  localSequence=findLocalSequence(prev, tour1, guess, tour2, after, ...
        d,sites, triangles, triangleGrid)
    %find the smooth local control sequence that satisfies the C1 criteria
    %and is safe
    %prev: the previous control point before tour1 (could be empty)
    %tour1,2: the end points that has to pass within +-d bounding box
    %after: the control point after tour2 (could be empty)
    %guess: the first guess of one in-between control point
    %sites, triangles, siteGrid, triangleGrid: terrain information
    
    localSequence=[(3*tour1-guess)./2, tour1, (tour1+guess)./2, guess./2+(tour1+tour2)./4, (tour2+guess)./2, tour2, (3*tour2-guess)./2];
    correspondingTriangles=findLocalTriangle(localSequence, sites, triangles, triangleGrid);
    t=0;
    while ~isempty(t)
        lambda=1;
        while 1
            localSequence=optimizeControlPoints(tour1, tour2, d, prev, after,  ...
                lambda, localSequence, correspondingTriangles, sites, triangles);
            if isempty(localSequence)
                break;
            end
            newTriangles=findLocalTriangle(localSequence, sites, triangles, triangleGrid);
            drawTrajectory(1,localSequence,sites);
            if newTriangles==correspondingTriangles
                break;
            else
                correspondingTriangles=newTriangles;
                lambda=lambda*2;
            end
        end
        if isempty(localSequence)
            localSequence=createNewSequence(correspondingTriangles, tour1, guess, tour2);
            correspondingTriangles=findLocalTriangle(localSequence, sites, triangles, triangleGrid);
        else
            [localSequence, correspondingTriangles]=addPoint(localSequence, sites, triangles, triangleGrid);
            if length(correspondingTriangles)==length(newTriangles)
                break;
            end
        end
    end
end